package com.wholesmart.service.impl;

import java.util.List;
import java.util.Map;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wholesmart.common.bean.Page;
import com.wholesmart.mapper.DepartmentMapper;
import com.wholesmart.mapper.entity.Department;
import com.wholesmart.service.DepartmentService;

@Service
public class DepartmentServiceImpl implements DepartmentService {
	@Autowired
	private DepartmentMapper departmentMapper;

	@Override
	public Department getById(Long id) {
		return departmentMapper.selectDepartmentBy(id);
	}

	@Override
	public Page<Department> getPage(Map<String, Object> params) {
		Page<Department> resultPage = new Page<>();
		// page参数
		Object page = params.get("page");
		BeanUtils.copyProperties(page, resultPage);
		// 条件参数
		Object condition = params.get("condition");
		List<Department> records = departmentMapper.selectPage(page, condition);
		long total = departmentMapper.countForSelectPage(condition);
		resultPage.setRecords(records);
		resultPage.setTotal(total);
		return resultPage;
	}

	@Override
	public String save(Department entity) {
		if (entity.getId() == null) {
			departmentMapper.insert(entity);
		} else {
			departmentMapper.updateById(entity);
		}
		return entity.getId().toString();
	}

	@Override
	public void deleteById(Long id) {
		departmentMapper.deleteById(id);
	}

	@Override
	public List<Department> recurDepartmentsById(Long id) {
		// TODO Auto-generated method stub
		return null;
	}
}
